//
//  FTQMineController.m
//  xiangmu
//
//  Created by apple on 2019/8/14.
//  Copyright © 2019 rzt. All rights reserved.
//

#import "FTQMineController.h"
#import "FTQPersonalController.h"
#import "SugViewController.h"
#import "FTQLoginController.h"
#import "AboutViewController.h"
#import "GPCollectViewController.h"
#import "GPCollectViewController.h"
#import "MyMessageController.h"
#import "MyHeyueController.h"
#import "GPAccountViewController.h"

@interface FTQMineController ()
@property(strong,nonatomic)NSMutableArray* dataArr;
@end

@implementation FTQMineController

-(void)viewWillAppear:(BOOL)animated{
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    [self.dataArr removeAllObjects];
    [self.dataArr addObjectsFromArray:kUserDefaultObjectForKey(@"user")];
    
    if (self.dataArr.count!=0) {
        //头像赋值
        if (self.dataArr[self.number][@"headimg"]==nil) {
            self.smallimage.image=[UIImage imageNamed:@"默认头像"];
            self.bigImg.image=[UIImage imageNamed:@"默认头像背景"];
        }else{
            UIImage *image = [UIImage imageWithData: self.dataArr[self.number][@"headimg"]];
            self.smallimage.image=image;
            self.bigImg.image=image;
        }
        //昵称label
        if (self.dataArr[self.number][@"nickname"]==nil) {
            self.nicknameLabel.text=self.dataArr[self.number][@"username"];
        }else{
            self.nicknameLabel.text=self.dataArr[self.number][@"nickname"];
        }
    }else{
        self.smallimage.image=[UIImage imageNamed:@"默认头像"];
        self.nicknameLabel.text=@"未登录";
         self.bigImg.image=[UIImage imageNamed:@"默认头像背景"];
    }
}

-(void)viewWillDisappear:(BOOL)animated{
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.bigImg.userInteractionEnabled=YES;
    self.smallimage.userInteractionEnabled=YES;
    self.scrollView.contentSize=CGSizeMake(0, 600);
    
    self.dataArr=[[NSMutableArray alloc] init];
    [self.dataArr addObjectsFromArray:kUserDefaultObjectForKey(@"user")];
    
    if (self.dataArr.count!=0) {
        //头像赋值
        if (self.dataArr[self.number][@"headimg"]==nil) {
            self.smallimage.image=[UIImage imageNamed:@"默认头像"];
            self.bigImg.image=[UIImage imageNamed:@"默认头像背景"];
        }else{
            UIImage *image = [UIImage imageWithData: self.dataArr[self.number][@"headimg"]];
            self.smallimage.image=image;
            self.bigImg.image=image;
        }
        //昵称label
        if (self.dataArr[self.number][@"nickname"]==nil) {
            self.nicknameLabel.text=self.dataArr[self.number][@"username"];
        }else{
            self.nicknameLabel.text=self.dataArr[self.number][@"nickname"];
        }
    }else{
        self.smallimage.image=[UIImage imageNamed:@"默认头像"];
        self.nicknameLabel.text=@"未登录";
        self.bigImg.image=[UIImage imageNamed:@"默认头像背景"];
    }
}


- (IBAction)imgBtnTap:(id)sender {
    FTQPersonalController *personal=[[FTQPersonalController alloc] init];
    personal.block = ^(id model) {
        if ([model isEqualToString:@"nologin"]) {
            //测试登录
            FTQLoginController* login=[[FTQLoginController alloc] init];
            UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:login];
            [self presentViewController:uiNavC animated:YES completion:nil];
        }
    };
    [self.navigationController pushViewController:personal animated:YES];
}

- (IBAction)collectBtnTap:(id)sender {
    GPCollectViewController* gp=[[GPCollectViewController alloc] init];
    [self.navigationController pushViewController:gp animated:YES];
}

- (IBAction)questionBtnTap:(id)sender {
    SugViewController* suggest=[[SugViewController alloc] init];
    [self.navigationController pushViewController:suggest animated:YES];
}

- (IBAction)AboutUsBtnTap:(id)sender {
    AboutViewController* about=[[AboutViewController alloc] init];
    [self.navigationController pushViewController:about animated:YES];
}

//宏伟
- (IBAction)zhanghuBtnTap:(id)sender {
    if ([self.dataArr[self.number][@"password"] isEqualToString:@"我是游客"]) {
        [self.view makeToast:@"游客无法使用账户哦~"
                    duration:2.0
                    position:CSToastPositionCenter];
    }else{
        GPAccountViewController *avc = [[GPAccountViewController alloc] init];
        avc.navTitle = @"我的账户";
        [self.navigationController pushViewController:avc animated:YES];
    }


}

- (IBAction)heyueBtnTap:(id)sender {
    MyHeyueController* heyue=[[MyHeyueController alloc] init];
     [self.navigationController pushViewController:heyue animated:YES];
}
- (IBAction)xiaoxiBtnTap:(id)sender {
    MyMessageController* message=[[MyMessageController alloc] init];
    [self.navigationController pushViewController:message animated:YES];
}

- (IBAction)shezhiTap:(id)sender {
    FTQPersonalController *personal=[[FTQPersonalController alloc] init];
    personal.block = ^(id model) {
        if ([model isEqualToString:@"nologin"]) {
            //测试登录
            FTQLoginController* login=[[FTQLoginController alloc] init];
            UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:login];
            [self presentViewController:uiNavC animated:YES completion:nil];
        }
    };
    [self.navigationController pushViewController:personal animated:YES];
}
@end
